/**
 * 显示充值地址和数量
 */
function changeQuestionType(){
	var questionType = document.getElementById("questionType").value;
	if(questionType == 0 || questionType == 1){
		document.getElementById("addressLi").style.display = "";
		document.getElementById("amountLi").style.display = "";
	}else{
		document.getElementById("addressLi").style.display = "none";
		document.getElementById("amountLi").style.display = "none";
	}
}
/**
 * 提交问题
 */
function submitQuestion(oldphone){
	if(document.getElementById("address")!=null){
		var address = document.getElementById("address").value;
	}
	if(document.getElementById("amount")!=null){
		var amount = document.getElementById("amount").value;
	}
	var desc = document.getElementById("desc").value;
	var qtoken = document.getElementById("qtoken").value;
//	var questionPath = document.getElementById("questionFile").value;
	var setflag = document.getElementById("setFlagType").value;
	var name;
	var phone;
	var questionType;
	var imgfile = document.getElementById("uploadFile");
	var file = imgfile.files[0];
	
	if(setflag == 2){
		name = document.getElementById("name").value;
		phone = document.getElementById("phoneNumberHidden").value;
	}else{
		name = document.getElementById("name").value;
		phone = document.getElementById("phone").value;
	}
	questionType = document.getElementById("questionType").value;
	
	if(questionType == -1){
		document.getElementById("errorMsg").innerHTML = questionjs1;
		return;
	}else{
		document.getElementById("errorMsg").innerHTML = "&nbsp;";
	}
	/*if(questionType == 0 || questionType == 1){
		if(address == "" || address.length < 20){
			document.getElementById("addressMsg").innerHTML = questionjs2;
			return;
		}else{
			var start = address.substring(0,1);
			if(questionType == 0 && start != "1"){
				document.getElementById("addressMsg").innerHTML = questionjs3;
				return;
			}
			if(questionType == 1 && start != "L"){
				document.getElementById("addressMsg").innerHTML = questionjs4;
				return;
			}
			document.getElementById("addressMsg").innerHTML = "&nbsp;";
		}
		if(amount == ""){
			document.getElementById("amountMsg").innerHTML = questionjs5;
			return;
		}
		document.getElementById("amountMsg").innerHTML = "&nbsp;";
	}*/
	if(desc == ""){
		document.getElementById("errorMsg").innerHTML = questionjs6;
		return;
	}else{
		document.getElementById("errorMsg").innerHTML = "&nbsp;";
	}
	if(desc.length > 1000){
		document.getElementById("errorMsg").innerHTML = questionjs7;
		return;
	}else{
		document.getElementById("errorMsg").innerHTML = "&nbsp;";
	}
	//允许姓名为空
//	if(name == ""){
//		document.getElementById("errorMsg").innerHTML = questionjs8;
//		return;
//	}else{
//		document.getElementById("errorMsg").innerHTML = "&nbsp;";
//	}
	if(phone == ""){
		document.getElementById("errorMsg").innerHTML = questionjs9;
		return;
	}else{
		document.getElementById("errorMsg").innerHTML = "&nbsp;";
	}
	
	var reg=/^[^0-9]+$/;
	var str=phone.substr(1);
	var reg1=/^((176)|(177)|(178)|(170)|(173)|(171)|(13[0-9])|(14[0-9])|(15[^4,\\d])|(18[0-9]))\d{8}$/;
	var reg2=/^\+86((176)|(177)|(178)|(170)|(173)|(171)|(13[0-9])|(14[0-9])|(15[^4,\\d])|(18[0-9]))\d{8}$/;
	var reg3=/^\+[0-9]{1,4}?\d{6,11}$/;
	
	if(phone == ""){
		document.getElementById("errorMsg").innerHTML = questionjs9;
		return;
	}else if(phone.length<2){
		document.getElementById("errorMsg").innerHTML = questionjs9;
		return;
	}else if(oldphone!=phone&&reg.test(str)){
		document.getElementById("errorMsg").innerHTML = questionjs9;
		return;
	}else if(oldphone!=phone&&!reg1.test(phone)&&!reg2.test(phone)&&!reg3.test(phone)){
		document.getElementById("errorMsg").innerHTML = questionjs9;
		return;
	}else{
		document.getElementById("errorMsg").innerHTML = "&nbsp;";
	}
	
	
	var formdata = new FormData(); 
	
	formdata.append("uploadFile",file);
	formdata.append("questionType",questionType);
	formdata.append("address",address);
	formdata.append("amount",amount);
	formdata.append("desc",desc);
	formdata.append("name",name);
	formdata.append("phone",phone);
	formdata.append("qtoken",qtoken);
	jQuery.ajax({  
        url: "/question/submitQuestion.do?random="+Math.round(Math.random()*100),  
        type: 'POST',  
        data: formdata,  
        dataType: 'JSON',  
        cache: false,  
        processData: false,  
        contentType: false
    }).done(function(data){
    	if(data == -1){
			document.getElementById("addressMsg").innerHTML = questionjs2;
		}else if(data == -2){
			document.getElementById("amountMsg").innerHTML = questionjs5;
		}else if(data == -3){
			document.getElementById("errorMsg").innerHTML = questionjs6;
		}else if(data == -4){
			document.getElementById("errorMsg").innerHTML = questionjs8;
		}else if(data == -5){
			//TODO　提示绑定手机
			document.getElementById("errorMsg").innerHTML = questionjs9;
		}else if(data == 0){
			//成功
			waitingStation("submitQuestionbutton",insubmiting);
			window.location.href = "/question/questionColumn.do";
		}else if(data == 2){
			document.getElementById("errorMsg").innerHTML = questionjs10;
		}else if(data == 4){
			document.getElementById("errorMsg").innerHTML = donotresubmit;
		}else if(data == -6){
			document.getElementById("addressMsg").innerHTML = questionjs3;
		}else if(data == -7){
			document.getElementById("addressMsg").innerHTML = questionjs4;
		}else if(data == -8){
			document.getElementById("errorMsg").innerHTML = questionjs11;
		}else if(data == -9){
			document.getElementById("errorMsg").innerHTML = questionjs7;
		}else{
			// 提交失败
			document.getElementById("errorMsg").innerHTML = rechargeusdsubfailure;
		}
    });
	
	
}
/**
 * 提交回复
 */
function submitQuestionReply(id){
	var reply = document.getElementById("reply").value;
	if(reply == ""){
		document.getElementById("errorMsg").innerHTML = questionjs12;
		return;
	}else{
		document.getElementById("errorMsg").innerHTML = "&nbsp;";
	}
	if(reply.length>1000){
		document.getElementById("errorMsg").innerHTML = questionjs13;
		return;
	}else{
		document.getElementById("errorMsg").innerHTML = "&nbsp;";
	}
	var url = "/question/submitQuestionReply.do?random="+Math.round(Math.random()*100);
	var param={qid:id,reply:reply};
	jQuery.post(url,param,function(data){
		if(data == -1){
			document.getElementById("errorMsg").innerHTML = questionjs12;
		}else if(data == -2){
			document.getElementById("errorMsg").innerHTML = questionjs14;
		}else if(data == 0){
			//成功
			window.location.href = "/question/seeQuestion.do?qid="+id;
		}else if(data == 2){
			document.getElementById("errorMsg").innerHTML = questionjs10;
		}else if(data == -3){
			document.getElementById("errorMsg").innerHTML = questionjs13;
		}else if(data == -4){
			document.getElementById("errorMsg").innerHTML = questionjs15;
		}
	});
}
/**
 * 撤销
 */
function cancelQuestion(id){
	var currentPage = document.getElementById("currentPage").value;
	var url = "/question/cancelQuestion.do?qid="+id+"&currentPage="+currentPage+"&random="+Math.round(Math.random()*100);
	window.location.href = url;
}

/**
 * 提交评价
 */
function getRadioValue(name){
	var obj =document.getElementsByName(name);
	var value = "";
	for(var i=0;i<obj.length;i++){
	    if(obj.item(i).checked){
	    	value=obj.item(i).getAttribute("value");  
	        break;
	     }else{
	    	 continue;
	  }
	}
	return value;
}

function submitSatisfaction(){
	var satisfaction = getRadioValue("satisfaction");
	var id = document.getElementById("questionId").value;
	var comment = document.getElementById("comment").value;
	if(comment.length>200){
		document.getElementById("errorMsg").innerHTML = get$("questionjs200");
		return;
	}else{
		document.getElementById("errorMsg").innerHTML = "&nbsp;";
	}
	var url = "/question/submitSatisfaction.do?random="+Math.round(Math.random()*100);
	var param={qid:id,comment:comment,satisfaction:satisfaction};
	jQuery.post(url,param,function(data){
		if(data == -1){
			document.getElementById("errorMsg").innerHTML = get$("questionjs200");
		}else if(data == -2){
			document.getElementById("errorMsg").innerHTML = questionjs16;
		}else if(data == 0){
			window.location.href= "/question/questionColumn.do?type=1";
		}
	});
}
function seeQuestion(qid,type){
	window.location.href= "/question/seeQuestion.do?qid="+qid+"&type="+type;
} 
function showEvaluationPre(id){
	dialogBoxShadow();
	document.getElementById("seeQuestion").style.display="";
	document.getElementById("questionId").value = id;
}
function closeWithdraw(){
	dialogBoxHidden();
	document.getElementById('seeQuestion').style.display = 'none';
}

function alertWrite(textid) {
	var text = document.getElementById(textid);
	var supplywrite = document.getElementById("supplywrite");
	var supplynum = document.getElementById("supplynum");
	var overwrite = document.getElementById("overwrite");
	var overnum = document.getElementById("overnum");
	
	var num = 1000 - text.value.length;
	if(num>=0){
		if(supplywrite.style.display =="none"){
			supplywrite.style.display="";
			overwrite.style.display="none";
		}
		supplynum.innerHTML = num;
	}else{
		if(overwrite.style.display =="none"){
			overwrite.style.display="";
			supplywrite.style.display="none";
		}
		overnum.innerHTML = num*-1;
	}
}
function checkImage() {
	var checkClick = document.getElementById("checkClick");
	var questionImage = document.getElementById("questionImage");
	checkClick.style.display="none";
	questionImage.style.display="";
}
function isAllowExt(fileName){
	var allowFileExt = new Array(".jpg",".jpeg",".png");
	var suffix =fileName.substr(fileName.lastIndexOf(".")).toLowerCase();
	for(var i=0;i<allowFileExt.length;i++){
		if(suffix == allowFileExt[i]){
			return true;
		}
	}
	return false;
}

function swfselectAgain() {
    jQuery("#upload_org_code_img").attr("src","");
    jQuery("#upload_org_code_img").hide();
    var swfu = jQuery.swfupload.getInstance('#swfupload-control');
    swfu.setButtonDisabled(false);
    jQuery("#afterUpload").hide();
    jQuery("#questionFile").val("");
}

